home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1999 July: Mac OS SDK / Dev.CD Jul 99 SDK1.toast / Development Kits / Mac OS / Interfaces&Libraries / Universal / Interfaces / PInterfaces / UnicodeUtilities.p < prev    next >
Encoding:
Text File  |  1998-08-17  |  12.5 KB  |  292 lines  |  [TEXT/MPS ]

  1. {
  2.      File:        UnicodeUtilities.p
  3.  
  4.      Contains:    Types, constants, prototypes for Unicode Utilities (Unicode input and text utils)
  5.  
  6.      Version:    Technology:    Allegro
  7.                  Release:    Universal Interfaces 3.2
  8.  
  9.      Copyright:    © 1997-1998 by Apple Computer, Inc., all rights reserved.
  10.  
  11.      Bugs?:        For bug reports, consult the following page on
  12.                  the World Wide Web:
  13.  
  14.                      http://developer.apple.com/bugreporter/
  15.  
  16. }
  17. {$IFC UNDEFINED UsingIncludes}
  18. {$SETC UsingIncludes := 0}
  19. {$ENDC}
  20.  
  21. {$IFC NOT UsingIncludes}
  22.  UNIT UnicodeUtilities;
  23.  INTERFACE
  24. {$ENDC}
  25.  
  26. {$IFC UNDEFINED __UNICODEUTILITIES__}
  27. {$SETC __UNICODEUTILITIES__ := 1}
  28.  
  29. {$I+}
  30. {$SETC UnicodeUtilitiesIncludes := UsingIncludes}
  31. {$SETC UsingIncludes := 1}
  32.  
  33. {$IFC UNDEFINED __MACTYPES__}
  34. {$I MacTypes.p}
  35. {$ENDC}
  36.  
  37.  
  38. {$PUSH}
  39. {$ALIGN MAC68K}
  40. {$LibExport+}
  41.  
  42. {
  43.    -------------------------------------------------------------------------------------------------
  44.    CONSTANTS & DATA STRUCTURES
  45.    -------------------------------------------------------------------------------------------------
  46. }
  47. {
  48.    -------------------------------------------------------------------------------------------------
  49.    UCKeyOutput & related stuff
  50.    The interpretation of UCKeyOutput depends on bits 15-14.
  51.    If they are 01, then bits 0-13 are an index in UCKeyStateRecordsIndex (resource-wide list).
  52.    If they are 10, then bits 0-13 are an index in UCKeySequenceDataIndex (resource-wide list),
  53.      or if UCKeySequenceDataIndex is not present or the index is beyond the end of the list,
  54.      then bits 0-15 are a single Unicode character.
  55.    Otherwise, bits 0-15 are a single Unicode character; a value of 0xFFFE-0xFFFF means no character
  56.      output.
  57.    UCKeyCharSeq is similar, but does not support indices in UCKeyStateRecordsIndex. For bits 15-14:
  58.    If they are 10, then bits 0-13 are an index in UCKeySequenceDataIndex (resource-wide list),
  59.      or if UCKeySequenceDataIndex is not present or the index is beyond the end of the list,
  60.      then bits 0-15 are a single Unicode character.
  61.    Otherwise, bits 0-15 are a single Unicode character; a value of 0xFFFE-0xFFFF means no character
  62.      output.
  63.    -------------------------------------------------------------------------------------------------
  64. }
  65.  
  66.  
  67. TYPE
  68.     UCKeyOutput                            = UInt16;
  69.     UCKeyCharSeq                        = UInt16;
  70.  
  71. CONST
  72.     kUCKeyOutputStateIndexMask    = $4000;
  73.     kUCKeyOutputSequenceIndexMask = $8000;
  74.     kUCKeyOutputTestForIndexMask = $C000;                        {  test bits 14-15 }
  75.     kUCKeyOutputGetIndexMask    = $3FFF;                        {  get bits 0-13 }
  76.  
  77. {
  78.    -------------------------------------------------------------------------------------------------
  79.    UCKeyStateRecord & related stuff
  80.    The UCKeyStateRecord information is used as follows. If the current state is zero,
  81.    output stateZeroCharData and set the state to stateZeroNextState. If the current state
  82.    is non-zero and there is an entry for it in stateEntryData, then output the corresponding
  83.    charData and set the state to nextState. Otherwise, output the state terminator from
  84.    UCKeyStateTerminators for the current state (or nothing if there is no UCKeyStateTerminators
  85.    table or it has no entry for the current state), then output stateZeroCharData and set the
  86.    state to stateZeroNextState.
  87.    -------------------------------------------------------------------------------------------------
  88. }
  89.  
  90.  
  91. TYPE
  92.     UCKeyStateRecordPtr = ^UCKeyStateRecord;
  93.     UCKeyStateRecord = RECORD
  94.         stateZeroCharData:        UCKeyCharSeq;
  95.         stateZeroNextState:        UInt16;
  96.         stateEntryCount:        UInt16;
  97.         stateEntryFormat:        UInt16;
  98.                                                                         {  This is followed by an array of stateEntryCount elements }
  99.                                                                         {  in the specified format. Here we just show a dummy array. }
  100.         stateEntryData:            ARRAY [0..0] OF UInt32;
  101.     END;
  102.  
  103. {
  104.    Here are the codes for entry formats currently defined.
  105.    Each entry maps from curState to charData and nextState.
  106. }
  107.  
  108. CONST
  109.     kUCKeyStateEntryTerminalFormat = $0001;
  110.     kUCKeyStateEntryRangeFormat    = $0002;
  111.  
  112. {
  113.    For UCKeyStateEntryTerminal -
  114.    nextState is always 0, so we don't have a field for it
  115. }
  116.  
  117.  
  118. TYPE
  119.     UCKeyStateEntryTerminalPtr = ^UCKeyStateEntryTerminal;
  120.     UCKeyStateEntryTerminal = RECORD
  121.         curState:                UInt16;
  122.         charData:                UCKeyCharSeq;
  123.     END;
  124.  
  125. {
  126.    For UCKeyStateEntryRange -
  127.    If curState >= curStateStart and curState <= curStateStart+curStateRange,
  128.    then it matches the entry, and we transform charData and nextState as follows:
  129.    If charData < 0xFFFE, then charData += (curState-curStateStart)*deltaMultiplier
  130.    If nextState != 0, then nextState += (curState-curStateStart)*deltaMultiplier
  131. }
  132.     UCKeyStateEntryRangePtr = ^UCKeyStateEntryRange;
  133.     UCKeyStateEntryRange = RECORD
  134.         curStateStart:            UInt16;
  135.         curStateRange:            SInt8;
  136.         deltaMultiplier:        SInt8;
  137.         charData:                UCKeyCharSeq;
  138.         nextState:                UInt16;
  139.     END;
  140.  
  141. {
  142.    -------------------------------------------------------------------------------------------------
  143.    UCKeyboardLayout & related stuff
  144.    The UCKeyboardLayout struct given here is only for the resource header. It specifies
  145.    offsets to the various subtables which each have their own structs, given below.
  146.    The keyboardTypeHeadList array selects table offsets that depend on keyboardType. The
  147.    first entry in keyboardTypeHeadList is the default entry, which will be used if the
  148.    keyboardType passed to UCKeyTranslate does not match any other entry - i.e. does not fall
  149.    within the range keyboardTypeFirst..keyboardTypeLast for some entry. The first entry
  150.    should have keyboardTypeFirst = keyboardTypeLast = 0.
  151.    -------------------------------------------------------------------------------------------------
  152. }
  153.     UCKeyboardTypeHeaderPtr = ^UCKeyboardTypeHeader;
  154.     UCKeyboardTypeHeader = RECORD
  155.         keyboardTypeFirst:        UInt32;                                    {  first keyboardType in this entry }
  156.         keyboardTypeLast:        UInt32;                                    {  last keyboardType in this entry }
  157.         keyModifiersToTableNumOffset: ByteOffset;                        {  required }
  158.         keyToCharTableIndexOffset: ByteOffset;                            {  required }
  159.         keyStateRecordsIndexOffset: ByteOffset;                            {  0 => no table }
  160.         keyStateTerminatorsOffset: ByteOffset;                            {  0 => no table }
  161.         keySequenceDataIndexOffset: ByteOffset;                            {  0 => no table }
  162.     END;
  163.  
  164.     UCKeyboardLayoutPtr = ^UCKeyboardLayout;
  165.     UCKeyboardLayout = RECORD
  166.                                                                         {  header only; other tables accessed via offsets }
  167.         keyLayoutHeaderFormat:    UInt16;                                    {  =kUCKeyLayoutHeaderFormat }
  168.         keyLayoutDataVersion:    UInt16;                                    {  0x0100 = 1.0, 0x0110 = 1.1, etc. }
  169.         keyLayoutFeatureInfoOffset: ByteOffset;                            {  may be 0                                     }
  170.         keyboardTypeCount:        ItemCount;                                {  Dimension for keyboardTypeHeadList[]         }
  171.         keyboardTypeList:        ARRAY [0..0] OF UCKeyboardTypeHeader;
  172.     END;
  173.  
  174. {  ------------------------------------------------------------------------------------------------- }
  175.     UCKeyLayoutFeatureInfoPtr = ^UCKeyLayoutFeatureInfo;
  176.     UCKeyLayoutFeatureInfo = RECORD
  177.         keyLayoutFeatureInfoFormat: UInt16;                                {  =kUCKeyLayoutFeatureInfoFormat }
  178.         reserved:                UInt16;
  179.         maxOutputStringLength:    UniCharCount;                            {  longest possible output string }
  180.     END;
  181.  
  182. {  ------------------------------------------------------------------------------------------------- }
  183.     UCKeyModifiersToTableNumPtr = ^UCKeyModifiersToTableNum;
  184.     UCKeyModifiersToTableNum = RECORD
  185.         keyModifiersToTableNumFormat: UInt16;                            {  =kUCKeyModifiersToTableNumFormat }
  186.         defaultTableNum:        UInt16;                                    {  For modifier combos not in tableNum[] }
  187.         modifiersCount:            ItemCount;                                {  Dimension for tableNum[] }
  188.         tableNum:                SInt8;
  189.                                                                         {  Then there is padding to a 4-byte boundary with bytes containing 0, if necessary. }
  190.     END;
  191.  
  192. {  ------------------------------------------------------------------------------------------------- }
  193.     UCKeyToCharTableIndexPtr = ^UCKeyToCharTableIndex;
  194.     UCKeyToCharTableIndex = RECORD
  195.         keyToCharTableIndexFormat: UInt16;                                {  =kUCKeyToCharTableIndexFormat }
  196.         keyToCharTableSize:        UInt16;                                    {  Max keyCode (128 for ADB keyboards) }
  197.         keyToCharTableCount:    ItemCount;                                {  Dimension for keyToCharTableOffsets[] (usually 6 to 12 tables) }
  198.         keyToCharTableOffsets:    ARRAY [0..0] OF ByteOffset;
  199.                                                                         {  Each offset in keyToCharTableOffsets is from the beginning of the resource to a }
  200.                                                                         {  table as follows: }
  201.                                                                         {     UCKeyOutput        keyToCharData[keyToCharTableSize]; }
  202.                                                                         {  These tables follow the UCKeyToCharTableIndex. }
  203.                                                                         {  Then there is padding to a 4-byte boundary with bytes containing 0, if necessary. }
  204.     END;
  205.  
  206. {  ------------------------------------------------------------------------------------------------- }
  207.     UCKeyStateRecordsIndexPtr = ^UCKeyStateRecordsIndex;
  208.     UCKeyStateRecordsIndex = RECORD
  209.         keyStateRecordsIndexFormat: UInt16;                                {  =kUCKeyStateRecordsIndexFormat }
  210.         keyStateRecordCount:    UInt16;                                    {  Dimension for keyStateRecordOffsets[] }
  211.         keyStateRecordOffsets:    ARRAY [0..0] OF ByteOffset;
  212.                                                                         {  Each offset in keyStateRecordOffsets is from the beginning of the resource to a }
  213.                                                                         {  UCKeyStateRecord. These UCKeyStateRecords follow the UCKeyToCharTableIndex. }
  214.                                                                         {  Then there is padding to a 4-byte boundary with bytes containing 0, if necessary. }
  215.     END;
  216.  
  217. {  ------------------------------------------------------------------------------------------------- }
  218.     UCKeyStateTerminatorsPtr = ^UCKeyStateTerminators;
  219.     UCKeyStateTerminators = RECORD
  220.         keyStateTerminatorsFormat: UInt16;                                {  =kUCKeyStateTerminatorsFormat }
  221.         keyStateTerminatorCount: UInt16;                                {  Dimension for keyStateTerminators[] (# of nonzero states) }
  222.         keyStateTerminators:    ARRAY [0..0] OF UCKeyCharSeq;
  223.                                                                         {  Note: keyStateTerminators[0] is terminator for state 1, etc. }
  224.                                                                         {  Then there is padding to a 4-byte boundary with bytes containing 0, if necessary. }
  225.     END;
  226.  
  227. {  ------------------------------------------------------------------------------------------------- }
  228.     UCKeySequenceDataIndexPtr = ^UCKeySequenceDataIndex;
  229.     UCKeySequenceDataIndex = RECORD
  230.         keySequenceDataIndexFormat: UInt16;                                {  =kUCKeySequenceDataIndexFormat }
  231.         charSequenceCount:        UInt16;                                    {  Dimension of charSequenceOffsets[] is charSequenceCount+1 }
  232.         charSequenceOffsets:    ARRAY [0..0] OF UInt16;
  233.                                                                         {  Each offset in charSequenceOffsets is in bytes, from the beginning of }
  234.                                                                         {  UCKeySequenceDataIndex to a sequence of UniChars; the next offset indicates the }
  235.                                                                         {  end of the sequence. The UniChar sequences follow the UCKeySequenceDataIndex. }
  236.                                                                         {  Then there is padding to a 4-byte boundary with bytes containing 0, if necessary. }
  237.     END;
  238.  
  239. {  ------------------------------------------------------------------------------------------------- }
  240. {  Current format codes for the various tables (bits 12-15 indicate which table) }
  241.  
  242.  
  243. CONST
  244.     kUCKeyLayoutHeaderFormat    = $1002;
  245.     kUCKeyLayoutFeatureInfoFormat = $2001;
  246.     kUCKeyModifiersToTableNumFormat = $3001;
  247.     kUCKeyToCharTableIndexFormat = $4001;
  248.     kUCKeyStateRecordsIndexFormat = $5001;
  249.     kUCKeyStateTerminatorsFormat = $6001;
  250.     kUCKeySequenceDataIndexFormat = $7001;
  251.  
  252.  
  253. {
  254.    -------------------------------------------------------------------------------------------------
  255.    Constants for keyAction parameter in UCKeyTranslate() 
  256.    -------------------------------------------------------------------------------------------------
  257. }
  258.  
  259.     kUCKeyActionDown            = 0;                            {  key is going down }
  260.     kUCKeyActionUp                = 1;                            {  key is going up }
  261.     kUCKeyActionAutoKey            = 2;                            {  auto-key down }
  262.     kUCKeyActionDisplay            = 3;                            {  get information for key display (as in Key Caps)             }
  263.  
  264. {
  265.    -------------------------------------------------------------------------------------------------
  266.    Bit assignments & masks for keyTranslateOptions parameter in UCKeyTranslate() 
  267.    -------------------------------------------------------------------------------------------------
  268. }
  269.  
  270.     kUCKeyTranslateNoDeadKeysBit = 0;                            {  Prevents setting any new dead-key states }
  271.  
  272.     kUCKeyTranslateNoDeadKeysMask = $00000001;
  273.  
  274. {
  275.    -------------------------------------------------------------------------------------------------
  276.    FUNCTION PROTOTYPES
  277.    -------------------------------------------------------------------------------------------------
  278. }
  279.  
  280. FUNCTION UCKeyTranslate(VAR keyLayoutPtr: UCKeyboardLayout; virtualKeyCode: UInt16; keyAction: UInt16; modifierKeyState: UInt32; keyboardType: UInt32; keyTranslateOptions: OptionBits; VAR deadKeyState: UInt32; maxStringLength: UniCharCount; VAR actualStringLength: UniCharCount; VAR unicodeString: UniChar): OSStatus;
  281.  
  282. {$ALIGN RESET}
  283. {$POP}
  284.  
  285. {$SETC UsingIncludes := UnicodeUtilitiesIncludes}
  286.  
  287. {$ENDC} {__UNICODEUTILITIES__}
  288.  
  289. {$IFC NOT UsingIncludes}
  290.  END.
  291. {$ENDC}
  292.